package Navigation;

import java.util.ArrayList;
import java.util.List;

import Items.Song;

public class PlaylistImpl implements Playlist 
{
	private List<Song> songList;
	private int position = 0;
	
	public PlaylistImpl() {
		this.songList = new ArrayList<Song>();
	}

	public void add(Song song) throws IllegalArgumentException
	{
		if (song ==null) 
		{
			throw new IllegalArgumentException();
		}
		
		if (this.songList.contains(song)) 
		{
			return;
		}
		this.songList.add(song);
	}

	public void remove(Song song) throws IllegalArgumentException
	{
		if (song ==null) 
		{
			throw new IllegalArgumentException();
		}
		
		if (this.songList.contains(song)) 
		{
			return;
		}
		this.songList.remove(song);
	}

	public Song getCurrentSong() 
	{
		if (this.position >= this.songList.size()) 
		{
			return this.songList.get(this.songList.size());
		}
		return this.songList.get(this.position);
	}

	public void move(Song song, int destination) throws IllegalArgumentException
	{
		if (song == null || 
			!this.songList.contains(song) ||
			destination >= this.songList.size()) 
		{
			throw new IllegalArgumentException();
		}
		this.songList.remove(song);
		this.songList.add(destination, song);
	}
	
}
